package com.eud.web.servlet;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.eud.entity.Movie;
import com.eud.entity.Admin;
import com.eud.service.MovieService;
import com.eud.service.AdminService;
import com.eud.service.impl.MovieServiceImpl;
import com.eud.service.impl.AdminServiceImpl;

/**
 * Servlet implementation class LogServlet
 */
@WebServlet("/AdminLogServlet")
public class AdminLogServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public AdminLogServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
    
    
    
    
    
    
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String adname = request.getParameter("adminname");
		String adpass = request.getParameter("adminpass");
		HttpSession session = request.getSession();
		
		AdminService as=new AdminServiceImpl();
		Admin a=as.query(adname);
		
		if(!("".equals(adname)) && !("".equals(adpass)) && (a!=null) && adpass.equals(a.getAdminPass())) {
		
			session.setAttribute("Admin", a);
			response.sendRedirect("crm_index.jsp");
			//request.getRequestDispatcher("crm_index.jsp").forward(request, response);
			
			
		}else {
			request.setAttribute("mes", "登录失败，用户名或密码错误");
			response.sendRedirect("CRM/admin_login.jsp");
		}
		
		
	}
		
	

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
